
import { makeAutoObservable } from 'mobx'
import { createContext, useContext } from 'react'

export interface BannerItem {
    /**  */
    AdvertType: number
    Describe: String
    ImgUrl: string
    Link: string
    Title: string
    Type: number
}

export interface BindItem {
    Author: string
    BID: number
    ChapterCount: number
    CoverUrl: string
    Description: string
    ExtensionUrl: string
    FocusCount: number
    GroupId: number
    ReadCount: number
    Score: number
    Status: number
    Title: string
    Type?: number
    Tags?: string
}

export interface BtnItem {
    BtnBindId: number  
    BtnId: number  
    BtnType: number  
    Describe: string
    DetailImage: string
    IconImage: string
    JumpUrl: string
    Title: string
    Type: number
}

export interface GroupItem {
    BindList: BindItem[]
    BtnList: BtnItem[]
    Describe: string
    DetailImage: string
    IconImage: string
    Id: number
    TempType: number
    Title: string
}

export interface NoticeItem {
    Describe: string
    ImgUrl: string
    Link: string
    Title: string
}

export interface PopAdItem extends NoticeItem {
    ShowTimes: number
}

export interface HomeData {
    bannerList: BannerItem[] 
    groupList: GroupItem[] 
    noticeList: NoticeItem[] 
    popAdList: PopAdItem[] 
}

class HomeStore {
    constructor() {
        makeAutoObservable(this)
        this.setCurData = this.setCurData.bind(this)
    }

    /** 轮播图 */
    bannerList: BannerItem[] = []
    
    /** 整个列表数据 */
    groupList: GroupItem[] = []
    
    /** 暂时没用 */
    noticeList: NoticeItem[] = []
    
    /** 公告弹窗 */
    popAdList: PopAdItem[] = []
    
    setCurData(data: HomeData) {
        this.bannerList = data.bannerList
        this.groupList = data.groupList
        this.noticeList = data.noticeList
        this.popAdList = data.popAdList
    }
    
    clear() {
        this.bannerList = []
        this.groupList = []
        this.noticeList = []
        this.popAdList = []
    }
}

const homeContent = createContext(new HomeStore())

export const useHomeStore = () => useContext(homeContent)
